/*
	Prepare Follow-up 1 Data for appending
*/

********************************************************************************
*  LOAD DATA AND KEEP ESSENTIAL VARIABLES ONLY
********************************************************************************

use "$data/1_raw/followup1_raw-deidentified.dta", clear

keep ///
	matricul sexe groupe ///
	s1qs1 ///
	birth_year ///
	s1q5a s1q5a_a s1q14 ///
	s1q15 s1q15a s1q15b s2q5 s2q5a ///
	s3q1 s3q2 s3q3 s3q4 s3q5 s3q6 s3q7 s3q8 s3q9 s3q10 ///
    s4q1 s4q2 s4q3 s4q4 s4q5 s4q6 s4q7 s4q8 s4q9 s4q10 s4q11 ///
    s4q12 s4q13 s4q14 s4q15 s4q16 s4q17 s4q18 s4q19 s4q20 s4q21 ///
    s4q22 s4q23 s4q24 s4q25 s4q26 s4q27 s4q28 s4q29 s4q30 s4q31 s4q32 ///
	s5q1 s5q2 s5q3 s5q5 s5q6 s5q7 s5q8 s5q9

********************************************************************************
*  VARIABLE RENAMING
********************************************************************************

// Core identification
rename matricul id
rename sexe sex
rename groupe treat

// Survey metadata
rename s1qs1 consent

// Demographics
rename birth_year yob

// Employment
rename s1q5a eif_pos
rename s1q14 last7d_hours_worked

// Earnings
rename s1q15 earn_change_aug19
rename s1q15a earn_dir_change_aug19
rename s1q15b earn_amount_change_aug19
rename s2q5 last7d_oj_earn
rename s2q5a last7d_oj_earn_range

// Big 5 personality
rename s3q1 big5_extrovert
rename s3q2 big5_critic
rename s3q3 big5_reliable
rename s3q4 big5_anxious
rename s3q5 big5_open
rename s3q6 big5_shy
rename s3q7 big5_sympathetic
rename s3q8 big5_disorganized
rename s3q9 big5_calm
rename s3q10 big5_conventional

// Conscientiousness traits
rename s4q1 trait_remorse_late
rename s4q2 trait_make_plan
rename s4q3 trait_work_goals
rename s4q4 trait_tidy
rename s4q5 trait_earlier_meet
rename s4q6 trait_avoid_late
rename s4q7 trait_follow_schedule
rename s4q8 trait_followup_method
rename s4q9 trait_attentive_others
rename s4q10 trait_others_dependent
rename s4q11 trait_set_clear_goals
rename s4q12 trait_keep_promises
rename s4q13 trait_avoid_procrast
rename s4q14 trait_fulfill_promises
rename s4q15 trait_set_high_standards
rename s4q16 trait_organize_schedule
rename s4q17 trait_change_setback
rename s4q18 trait_up_to_responsib
rename s4q19 trait_on_time
rename s4q20 trait_respect_engagements
rename s4q21 trait_work_hard
rename s4q22 trait_clean_up
rename s4q23 trait_orga_pers_spaces
rename s4q24 trait_others_count
rename s4q25 trait_focus_goals
rename s4q26 trait_make_plan_for_goal
rename s4q27 trait_late_meetings
rename s4q28 trait_keep_organized
rename s4q29 trait_keep_tidy
rename s4q30 trait_fulfill_duty
rename s4q31 trait_keep_trying_if_fail
rename s4q32 trait_manage_responsib

// Household characteristics
rename s5q1 hh_n_above_18
rename s5q2 hh_n_children
rename s5q3 hh_n_bedrooms
rename s5q5 hh_revenue_range_r1r2
rename s5q6 hh_formal_savings
rename s5q7 hh_informal_savings
rename s5q8 hh_formal_debt
rename s5q9 hh_informal_debt

********************************************************************************
*  CLEANING AND RECODING
********************************************************************************

gen survey_round = 2

* -------------------- ID -------------------- *

destring	id, replace

* -------------------- Sex -------------------- *

label def   sex 0 "Male" 1 "Female"
encode		sex, gen(sex_e) label(sex)
recode      sex_e (2=1) (3=0)
drop		sex
rename		sex_e sex

* -------------------- Treatment -------------------- *

label def   treat 0 "Control" 1 "Treatment"  
encode		treat, gen(treat_e) label(treat)
drop		treat
rename		treat_e treat

* -------------------- Consent -------------------- *

recode		consent (2=0)

label def	yesno 0 "No" 1 "Yes"
label val	consent yesno

keep if consent == 1

* -------------------- Work variables -------------------- *

mvdecode last7d_*, mv(-888 -999)
mvdecode earn_*, mv(-888 -999)  

* -------------------- Position at Eiffage -------------------- *

replace 	eif_pos = 1		if 		s1q5a_a == "Agent preventaire"
replace 	eif_pos = 15	if 		s1q5a_a == "Bile"
replace 	eif_pos = 11	if 		s1q5a_a == "OUVRIER SPECIAL" | s1q5a_a == "ouvrier specialiser en pasderelle" 
replace 	eif_pos = 16	if 		s1q5a_a == "Peintre"
replace 	eif_pos = 20 	if 		s1q5a_a == "Platre" | s1q5a_a == "plaquiste" 
replace 	eif_pos = 20 	if 		s1q5a_a == "Restauration"
replace 	eif_pos = 21	if 		s1q5a_a == "Soudeur"
replace 	eif_pos = 17	if 		s1q5a_a == "etenciete"

drop		s1q5a_a

label def	eif_pos ///
    1 "Security agent helper"	2 "Guardian"	///
    3 "Mason"					4 "Scrap dealer"	///
    5 "Form setter"				6 "Carpenter"	///
    7 "Laborer"					8 "Other"	///
    9 "Driver help"				10 "Topographer/Topographer helper"	///
    11 "Worker"					12 "Flag holder"	///
    13 "Specialized laborer/worker"  ///
    14 "Preventive agent"		15 "Bile"	///
    16 "Painter"				17 "Waterproofing" ///
    18 "Restauration"			19 "QHSE supervisor/manager"  ///
    20 "Plaster worker"			21 "Welder"	///
    21 "Crane helper" 			22 "Sanitation" ///
    23 "Cleaner team leader" 	///
    24 "Fosseur"				25 "Workhouse worker" ///
    26 "Multi-pole Network Worker" 	27 "Earthwork worker" 
                
label val	eif_pos eif_pos

* -------------- Change in Earnings since Aug 2019 --------------- *

recode 		earn_change_aug19 (2 = 0)
label value earn_change_aug19 yesno

recode		earn_dir_change_aug19 (2 = -1)

label def   direction_change ///
    1 "Increase" ///
    -1 "Decrease"

label value earn_dir_change_aug19 direction_change

label def salary_change_amount ///
    1 "Less than 5,000 CFAF" ///
    2 "5,001 - 10,000" ///
    3 "10,001 - 15,000" ///
    4 "15,001 - 20,000" ///
    5 "20,001 - 25,000" ///
    6 "25,001 - 30,000" ///
    7 "30,001 - 35,000" ///
    8 "35,001 - 40,000" ///
    9 "More than 40,000 CFAF"

label val 	earn_amount_change_aug19 salary_change_amount

* -----------  Earnings form Other Job in the last 7 days ------------ *

mvdecode 	last7d_oj_earn, mv(999)

label value last7d_oj_earn_range monthly_income_range

mvdecode 	earn_*, mv(-888 -999)

* -------------------- Big Five variables -------------------- *

mvdecode big5_*, mv(-888 -999)

* Recoding negative questions in order to have all items "higher values = better outcomes"
recode		big5_critic big5_anxious big5_shy big5_disorganized big5_conventional ///
            (1=5) (2=4) (3=3) (4=2) (5=1)

* -------------------- Conscientiousness traits -------------------- *

mvdecode trait_*, mv(-888 -999)

* Inverse the coding of answers to have "higher values = better outcomes"
recode		trait_* (1=5) (2=4) (3=3) (4=2) (5=1)

lab def		easiness ///
            5 "Very easy" ///
            4 "Fairly easy" ///
            3 "Neither easy nor difficult" ///
            2 "Fairly difficult" ///
            1 "Very difficult"
            
lab val		trait_* easiness

* ------------------- Household Information -------------------- * 

mvdecode 	hh_*, mv(-888 -999)

label def 	hh_formal_savings /// 
    0 "Nothing (0 FCFA)" ///
    1 "Less than 50,000 (FCFA)" ///
    2 "50,000-100,000" ///
    3 "100,000-150,000" ///
    4 "150,000-200,000" ///
    5 "200,000-250,000" ///
    6 "250,000 and more"

label value hh_formal_savings hh_informal_savings hh_formal_debt hh_informal_debt ///
    hh_formal_savings

********************************************************************************
*  ORDER VARIABLES AND SAVE
********************************************************************************

* Save harmonized baseline data
save "$data/2_processed/followup1_clean.dta", replace

********************************************************************************
*  END CODE
********************************************************************************
